import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

const useSession = false

const EXPIRE_DATE = 1 // 1天

export function getToken() {
  return useSession ? sessionStorage.getItem(TokenKey) : Cookies.get(TokenKey)
}

export function setToken(token) {
  return useSession ? sessionStorage.setItem(TokenKey, token) : Cookies.set(TokenKey, token, { expires: EXPIRE_DATE })
}

export function removeToken() {
  return useSession ? sessionStorage.removeItem(TokenKey) : Cookies.remove(TokenKey)
}

const RefreshTokenKey = 'Admin-REFRESH_TOKEN'

export function getRefreshToken() {
  return useSession ? sessionStorage.getItem(RefreshTokenKey) : Cookies.get(RefreshTokenKey)
}

export function setRefreshToken(token) {
  return useSession ? sessionStorage.setItem(RefreshTokenKey, token) : Cookies.set(RefreshTokenKey, token, { expires: EXPIRE_DATE })
}

export function removeRefreshToken() {
  return useSession ? sessionStorage.removeItem(RefreshTokenKey) : Cookies.remove(RefreshTokenKey)
}

export function getCache(key) {
  return useSession ? sessionStorage.getItem(key) : Cookies.get(key)
}

export function setCache(key, value, expireDate = EXPIRE_DATE) {
  return useSession ? sessionStorage.setItem(key, value) : Cookies.set(key, value, { expires: expireDate })
}

export function removeCache(key) {
  return useSession ? sessionStorage.removeItem(key) : Cookies.remove(key)
}

export function getStorage(key) {
  return localStorage.getItem(key)
}

export function setStorage(key, value) {
  return localStorage.setItem(key, value)
}

export function removeStorage(key) {
  return localStorage.removeItem(key)
}

